package cn.lin.controller;

import cn.lin.domain.Sign;
import cn.lin.domain.SignUser;
import cn.lin.service.SignService;
import cn.lin.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cn.Lin
 * @create 2024-12-04-15:57
 */
@RestController
@RequestMapping("/signIn")
public class SignController {

    @Autowired
    private SignService signService;

    @PostMapping("/add")
    public Object addSignIn(@RequestBody Sign sign){
        List<SignUser> signUserList = signService.initiateSignIn(sign);

        if (signUserList != null){
            return Result.ok("发起成功",signUserList);
        }
        return Result.error("发起失败");
    }

    @GetMapping("/signList")
    public Object listSignIn(@RequestParam("signId") Integer signId){
        List<SignUser> signUsers = signService.listUserBySignId(signId);

        if (signUsers != null){
            return Result.ok("获取签到列表成功",signUsers);
        }
        return Result.error("获取签到列表失败");
    }

    @PostMapping("/update")
    public Object updateSignIn(@RequestBody SignUser signUser){
        int ret = signService.updateSignInStu(signUser);

        if (ret != 0){
            return Result.ok("更新成功");
        }
        return Result.error("更新失败");
    }
}
